#include"comm.hpp"

int main()
{
    int r = creatFifo(NAMED_PIPE);
    //assert(r==-1);
    //std::cout<<r<<std::endl;
    (void)r;

    std::cout<<"server begin"<<std::endl;
    int rfd = open(NAMED_PIPE,O_RDONLY);
    std::cout<<"server end"<<std::endl;

    if(rfd<0)
    {
        perror("open");
        exit(-2);
    }

    char buffer[1024];

    while(true)
    {
        ssize_t n = read(rfd,buffer,sizeof(buffer)-1);
        if(n>0)
        {
            buffer[n] = 0;
            std::cout<<"get mseeage->"<<buffer<<std::endl;         
        }
        else if(n==0)
        {
            std::cout<<"client quit ! me too !"<<std::endl;
            break;
        }
        else
        {
            perror("read");
            break;
        }

    }
    close(rfd);
    removeFifo(NAMED_PIPE);
    return 0;
}